package com.yeswater.multithread.chapter2.test2_1.test9;

/**
 * author : yeswater
 * date : 2023/10/19
 *
 * 线程出现异常时,释放锁
 */

public class Service {

    synchronized public void testMethod() {
        if (Thread.currentThread().getName().equals("a")) {
            System.out.println("ThreadName=" + Thread.currentThread().getName() + " run beginTime=" + System.currentTimeMillis());
            int i = 1;
            while (i == 1) {
                if (("" + Math.random()).startsWith("0.123456")) {
                    System.out.println("ThreadName=" + Thread.currentThread().getName()
                            + "  run exceptionTime=" + System.currentTimeMillis());
                    Integer.parseInt("a");
                }
            }
        }
        else {
            System.out.println("Thread B run time=" + System.currentTimeMillis());
        }
    }

}
